let controls: { type: string; controlObj: any; }[] = []

const controlMgr = {
    // 全屏控件
    screenControl(map: any) {
        // 添加全屏控件
        const controlObj = map.addControl(new mapboxgl.FullscreenControl({ container: document.querySelector('body') }));
        controls.push({ type: 'screenControl', controlObj });
    },
    // 导航控件
    navControl(map: any) {
        // 添加导航控件
        const controlObj = map.addControl(new mapboxgl.NavigationControl());
        controls.push({ type: 'navControl', controlObj });
    },
    // 比例尺控件
    scaleControl(map: any) {
        // 添加比例尺控件
        const scale = new mapboxgl.ScaleControl({
            maxWidth: 120,
            unit: 'metric'
        });
        const controlObj = map.addControl(scale, 'bottom-left');
        controls.push({ type: 'scaleControl', controlObj });
    },
    // 移除控件  type: 'screenControl' | 'navControl' | 'scaleControl'
    removeControl(map: any, type: string) {
        controls.forEach((item: any) => {
            if (item.type === type) {
                map.removeControl(item.controlObj);
            }
        })
    }

}

export { controlMgr };